package util.essential.io;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Input {
	//Constants:

	//Attributes:
	private static Input instance = null;
	
	//Constructors: With Singleton pattern.
	private Input(){}
	public static Input getInstance(){
		if(instance==null){
			instance = new Input();
		}
		return instance;
	}

	//Methods:
	/**
	 * @return keyboard characters line with a default prompt.
	 */
	public String getString() {
		return getString("> ");
	}

	/**
	 * @return keyboard characters line with a user defined prompt.
	 */
	public String getString(String prompt) {
		do {
			try {
				BufferedReader buffer = new BufferedReader(
						new InputStreamReader(System.in));
				System.out.print(prompt);
				return buffer.readLine();
			} catch (IOException e) {
				System.err.println(e.toString());
			}
		} while (true);
	}
}
